using AnimCollections;
using System;
using Unity.Mathematics;

namespace DA.AnimGraph {

    public struct InputMapping : IDisposable {
        public NativeSimpleArray<int2> mapping;

        public InputMapping(int2[] desc, ref GraphBuffer buffer) {
            if (desc == null || desc.Length == 0) {
                mapping = default;
            } else {
                buffer.MallocNativeSimpleArray(out mapping, desc);
            }
        }

        public int Check(int input) {
            if (!mapping.IsCreated) {
                return input;
            }
            for (int i = 0; i < mapping.Length; i++) {
                if (mapping[i].x == input) {
                    return mapping[i].y;
                }
            }
            return -1; // 使用范围外值，不引起变化
        }

        public void Dispose() {
            mapping.Dispose();
        }
    }
}